package com.yc.vote.controller;

import com.yc.vote.entity.Items;
import com.yc.vote.mapper.ItemsMapper;
import com.yc.vote.vo.Result;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.util.Arrays;

/**
 * <p>
 * 投票系统-题目选项表-9 前端控制器
 * </p>
 *
 * @author baomidou
 * @since 2024-04-14
 */
@RestController
@RequestMapping("/vote/items")
public class ItemsController {

    @Resource
    ItemsMapper itemsMapper;

    @PostMapping("rm")
    public Result rmById(@RequestBody Items items){

        itemsMapper.deleteById(items.getId());

        return new Result(1,"",items);
    }


    @PostMapping("up")
    public Result upById(@RequestBody Items items){

        itemsMapper.updateById(items);

        return new Result(1,"",items);
    }


    @PostMapping("add")
    public Result addItems(@RequestBody Items[] addItems){
        for (Items items : addItems) {
            itemsMapper.insert(items);
        }
        return new Result(1,"增加选项成功",addItems);
    }

}
